#ifndef SQLFORMATTER_H
#define SQLFORMATTER_H

#include <QString>
#include <QMap>
#include <QList>
#include <QRegularExpression>

class SQLFormatter
{
public:
    SQLFormatter();
    
    QString format(const QString &sql) const;
    void setIndentSize(int size);
    void setUppercaseKeywords(bool uppercase);
    
private:
    struct Token {
        enum Type {
            Keyword,
            Identifier,
            String,
            Number,
            Operator,
            Comment,
            Whitespace,
            Unknown
        };
        
        Type type;
        QString value;
        int position;
        
        Token(Type t, const QString &v, int pos) : type(t), value(v), position(pos) {}
    };
    
    QList<Token> tokenize(const QString &sql) const;
    QString reconstruct(const QList<Token> &tokens) const;
    bool isKeyword(const QString &word) const;
    QString formatKeyword(const QString &keyword) const;
    
    int m_indentSize;
    bool m_uppercaseKeywords;
    
    // SQL关键字列表
    mutable QMap<QString, bool> m_keywords;
};

#endif // SQLFORMATTER_H